package bintree.seachtree;

import bintree.avl.AVLTree;
import bintree.rb_tree.RBTree;

import java.util.ArrayList;
import java.util.List;

/**
 * 在1000w个有序数中测试AVL和红黑树的添加性能
 *
 * @author yuisama
 * @date 2022/03/10 11:54
 **/
public class Test2 {
    public static void main(String[] args) {
        int n = 20000000;
        List<Integer> testData = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            testData.add(i);
        }
        AVLTree<Integer> avlTree = new AVLTree<>();
        RBTree<Integer> rbTree = new RBTree<>();
        // testAVL
        Thread th1 = new Thread(() -> {
            long start = System.nanoTime();
            for (int i : testData) {
                avlTree.add(i);
            }
            long end = System.nanoTime();
            System.out.println("avl共耗时: " + (end - start) / 1000000000.0 + "s");
        });
        // testRBTree
        Thread th2 = new Thread(() -> {
            long start = System.nanoTime();
            for (int i : testData) {
                rbTree.add(i);
            }
            long end = System.nanoTime();
            System.out.println("RBTree共耗时: " + (end - start) / 1000000000.0 + "s");
        });
        th2.start();
        th1.start();
        System.out.println("main-over");
    }
}